package com.phiture.erp.basic.web.controller.api;

import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import com.phiture.erp.basic.api.pojo.resp.ErpSupplierResp;
import com.phiture.erp.basic.api.service.ErpSupplierApi;
import com.phiture.erp.basic.core.service.ErpSupplierService;
import com.phiture.erp.basic.dal.entity.ErpSupplierDO;
import com.phiture.erp.basic.web.convert.ErpSupplierConvertMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * @author YH
 * @date 2025/4/13
 */

@Service
@RequiredArgsConstructor
public class ErpSupplierApiServiceImpl implements ErpSupplierApi {
    private final ErpSupplierService supplierService;

    @Override
    public ErpSupplierResp validateSupplier(Long id) {
        ErpSupplierDO supplierDO = supplierService.validateSupplier(id);
        return ErpSupplierConvertMapper.INSTANCE.toErpSupplierResp(supplierDO);
    }

    @Override
    public Map<Long, ErpSupplierResp> getSupplierMap(Collection<Long> ids) {
        List<ErpSupplierDO> supplierList = supplierService.getSupplierList(ids);
        List<ErpSupplierResp> erpSupplierRespList = ErpSupplierConvertMapper.INSTANCE.toErpSupplierRespList(supplierList);
        return CollectionUtils.convertMap(erpSupplierRespList, ErpSupplierResp::getId);
    }
}
